<p>This is an issue when using <code>String#charCodeAt()</code> or <code>String.fromCharCode()</code> methods, which don’t properly handle Unicode
characters that require surrogate pairs.</p>
<h2>Why is this an issue?</h2>
<p>JavaScript strings use UTF-16 encoding internally. Some Unicode characters, like emojis and certain international characters, require two 16-bit
code units (called surrogate pairs) to represent a single character.</p>
<p>The older methods <code>charCodeAt()</code> and <code>fromCharCode()</code> work with individual UTF-16 code units. When dealing with characters
that use surrogate pairs, these methods only process the first code unit, leading to incorrect results.</p>
<p>For example, the emoji '🦄' (unicorn) has the Unicode code point U+1F984. In UTF-16, this becomes a surrogate pair. Using
<code>charCodeAt(0)</code> only returns the first part of this pair, not the complete character code.</p>
<p>The newer methods <code>codePointAt()</code> and <code>fromCodePoint()</code> understand Unicode code points properly. They handle surrogate pairs
correctly and return the actual Unicode code point value, ensuring your application works correctly with international text and emojis.</p>
<h3>What is the potential impact?</h3>
<p>Using the wrong methods can cause:</p>
<ul>
  <li> Incorrect character processing for emojis and international characters </li>
  <li> Data corruption when converting between characters and numeric codes </li>
  <li> Poor user experience for users with non-ASCII names or content </li>
  <li> Inconsistent behavior across different Unicode characters </li>
</ul>
<h3>How to fix?</h3>
<p>Replace <code>charCodeAt()</code> with <code>codePointAt()</code> to get the correct Unicode code point value.</p>
<h4>Non-compliant code example</h4>
<pre data-diff-id="1" data-diff-type="noncompliant">
const code = '🦄'.charCodeAt(0); // Noncompliant
</pre>
<h4>Compliant code example</h4>
<pre data-diff-id="1" data-diff-type="compliant">
const code = '🦄'.codePointAt(0);
</pre>
<h3>Documentation</h3>
<ul>
  <li> <a href="https://github.com/sindresorhus/eslint-plugin-unicorn#readme">eslint-plugin-unicorn</a> - Rule <a
  href="https://github.com/sindresorhus/eslint-plugin-unicorn/blob/HEAD/docs/rules/prefer-code-point.md">prefer-code-point</a> </li>
  <li> String.prototype.codePointAt() - <a
  href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt">MDN documentation for the codePointAt()
  method</a> </li>
  <li> String.fromCodePoint() - <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint">MDN
  documentation for the fromCodePoint() method</a> </li>
  <li> Unicode and JavaScript - <a href="https://mathiasbynens.be/notes/javascript-unicode">Comprehensive guide to Unicode handling in JavaScript</a>
  </li>
</ul>
